<template>
  <div class="login-container">
    <el-form
      :model="loginForm"
      :rules="loginRules"
      ref="loginForm"
      class="login-form" autoComplete="on" lable-posiiton="left">
      <div class="title-container">
        <h1 class="logo-name">宽</h1>
      </div>
      <el-form-item prop="username">
        <span class="svg-container svg-container-login">
          <svg-icon icon-class="iconzh1" />
        </span>
        <el-input
          @keyup.enter.native="handleLogin"
          name="username"
          v-model="loginForm.username"
          autoComlete="on" placeholder="username"></el-input>
      </el-form-item>

      <el-form-item prop="password">
        <span class="svg-container svg-container-login">
          <svg-icon icon-class="mima" />
        </span>
        <el-input
          @keyup.enter.native="handleLogin"
          :type="showPwd ? 'text' : 'password'"
          name="password"
          v-model="loginForm.password"
          autoComlete="on" placeholder="password"></el-input>
        <span @click="showPwd = !showPwd" class="show-pwd">
          <svg-icon :icon-class="showPwd ? 'yanjing-zheng' : 'yanjing-bi'"></svg-icon>
        </span>
      </el-form-item>

      <el-button
        @click="handleLogin"
        class="confirm-btn" type="primary">登陆
      </el-button>

    </el-form>
  </div>
</template>

<script>
  const isDev = process.env.NODE_ENV === 'development'

  export default {
    name: 'login',
    data() {
      return {
        showPwd: false,
        loginForm: {
          username: isDev ? 'admin' : '',
          password: isDev ? 123 : ''
        },
        loginRules: {
          username: [{
            required: true, trigger: 'blur', message: '请输入账号'
          }],
          password: [{
            required: true, trigger: 'blur', message: '请输入密码'
          }]
        }
      }
    },
    methods: {
      handleLogin() {
        this.$refs.loginForm.validate(async (valid) => {
          if (valid) {
            this.$store.dispatch('login', this.loginForm).then(() => {
              this.$router.replace({ path: '/' })
            })
          }
        })
      }
    }
  }
</script>


<style rel="stylesheet/scss" lang="scss">
  $bg: #2d3a4b;
  $light_gray: #eee;

  /* reset element-ui css */
  .login-container {
    .el-input {
      display: inline-block;
      height: 47px;
      width: 85%;
      input {
        background: transparent;
        border: 0px;
        -webkit-appearance: none;
        border-radius: 0px;
        padding: 12px 5px 12px 15px;
        color: $light_gray;
        height: 47px;
        &:-webkit-autofill {
          -webkit-box-shadow: 0 0 0px 1000px $bg inset !important;
          -webkit-text-fill-color: #fff !important;
        }
      }
    }
    .el-form-item {
      border: 1px solid rgba(255, 255, 255, 0.1);
      background: rgba(0, 0, 0, 0.1);
      border-radius: 5px;
      color: #454545;
    }
  }
</style>

<style lang="scss" scoped>
  $bg: #2d3a4b;
  $light_gray: #eee;
  $dark_gray: #889aa4;

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    color: #454545;
  }

  .login-container {
    position: fixed;
    height: 100%;
    width: 100%;
    background-color: $bg;
    .login-form {
      position: absolute;
      top: 40%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 400px;
      padding: 35px 35px 15px 35px;
    }
    .svg-container {
      padding: 6px 5px 6px 15px;
      color: $dark_gray;
      vertical-align: middle;
      width: 30px;
      display: inline-block;
      &_login {
        font-size: 20px;
      }
    }
    .title-container {
      position: relative;
      .logo-name {
        color: #e6e6e6;
        font-size: 100px;
        font-weight: 800;
        letter-spacing: -10px;
        margin-bottom: 10px;
        text-align: center;
      }
    }
    .show-pwd {
      position: absolute;
      right: 10px;
      top: 7px;
      font-size: 16px;
      color: $dark_gray;
      cursor: pointer;
      user-select: none;
    }
    .confirm-btn {
      width: 100%;
    }
  }
</style>
